//
//  KFWNotificationSystemCell.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/1/29.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//

#import "KFWNotificationSystemCell.h"
#import "Model_notificationSystem.h"
#import "UIImageView+WebCache.h"

@implementation KFWNotificationSystemCell
@synthesize label_time;
@synthesize label_content;
@synthesize label_title;
@synthesize imageview_content;
@synthesize imageview_line;

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        label_title = [UIUtils creatLabel];
        label_title.font = FontOfQuestionList;
        label_title.textColor = ColorOfQuestionList;
        label_title.frame = CGRectZero;
        label_title.numberOfLines = 0;
        
        imageview_content = [[UIImageView alloc] init];
        imageview_content.frame = CGRectZero;
        imageview_content.hidden = YES;
        
        label_content = [UIUtils creatLabel];
        label_content.font = FontOfHelveticaBold(14);
        label_content.textColor = ColorOfQuestionList;
        label_content.frame = CGRectZero;
        label_content.hidden = YES;
        label_content.numberOfLines = 0;
        
        label_time = [UIUtils creatLabel];
        label_time.font = FontOfSystem(13);
        label_time.frame = CGRectZero;
        label_time.textColor = RGB(194, 194, 194);
        
        imageview_line = [[UIImageView alloc] init];
        
        [self addSubview:label_title];
        [self addSubview:imageview_content];
        [self addSubview:label_content];
        [self addSubview:label_time];
        [self addSubview:imageview_line];
    }
    return self;
}

- (void)changeNotificationSystemCellWith:(Model_notificationSystem *)system;
{
    if(system.string_isunread.integerValue == 0)
    {
        label_content.textColor = RGB(162, 162, 162);
        label_title.textColor = RGB(162, 162, 162);
    }
    else
    {
        label_content.textColor = ColorOfQuestionList;
        label_title.textColor = ColorOfQuestionList;
    }
    
    CGFloat height = 0;
    CGFloat titleHeight = [UIUtils heightFor:system.string_title withFont:FontOfQuestionList labWidth:MainScreenWidth - 15*2];
    self.label_title.text = system.string_title;
    self.label_title.frame = CGRectMake(15, 15, MainScreenWidth - 15*2, titleHeight);
    height = 15 + titleHeight + 15;
    
    if (system.string_contentimg && system.string_contentimg.length > 0) {
        self.imageview_content.hidden = NO;
        
        //图片大小290*74
        CGFloat scale = (MainScreenWidth - 15 * 2)/290.0;
        self.imageview_content.frame = CGRectMake(15, self.label_title.frame.origin.y + self.label_title.frame.size.height + 15, MainScreenWidth - 15 * 2, 74 * scale);
        [self.imageview_content sd_setImageWithURL:[NSURL URLWithString:system.string_contentimg] placeholderImage:[UIImage imageFileName:@"notificationsystemdefault.png"]];
        
        height = height + 74*scale + 15;
//        [self.imageview_content sd_setImageWithURL:[NSURL URLWithString:system.string_contentimg] placeholderImage:[UIImage imageFileName:@"notificationsystemdefault.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//            
//        }];
    }
    else
    {
        self.imageview_content.hidden = YES;
    }
    
    if (system.string_content && system.string_content.length > 0) {
        self.label_content.hidden = NO;
        self.label_content.text = system.string_content;
        CGFloat contentHeight = [UIUtils heightFor:system.string_content withFont:FontOfHelveticaBold(14) labWidth:MainScreenWidth - 15*2];
        self.label_content.frame = CGRectMake(15, height, MainScreenWidth - 15*2, contentHeight);
        height = height + contentHeight + 15;
    }
    else
    {
        self.label_content.hidden = YES;
    }
    self.label_time.frame = CGRectMake(15, height, 150, 15);
    self.label_time.text = system.string_time;
    
    imageview_line.frame = CGRectMake(0, label_time.frame.origin.y + label_time.frame.size.height + 9, MainScreenWidth, 1);
    imageview_line.backgroundColor = RGB(220, 220, 220);
}

@end
